package com.example.kill.controller;

import com.example.kill.pojo.KillUser;
import com.example.kill.redis.RedisService;
import com.example.kill.redis.UserKey;
import com.example.kill.result.Result;
import com.example.kill.service.KillUserService;
import org.apache.ibatis.io.ResolverUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;

@Controller
public class HelloController {

    @Autowired
    private KillUserService userService;

    @Autowired
    private RedisService redisService;


    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "Hello world" ;
    }


    @RequestMapping("/redis/set")
    @ResponseBody
    public Result<Boolean> redisSet(){

        KillUser user = new KillUser();
        user.setId(2L);
        user.setNickName("Jack");
        user.setPassword("1231233");
        user.setLastLoginDate(new Date());
        user.setRegisterDate(new Date());
        user.setSalt("!23123");
        boolean flag = redisService.set(UserKey.getById,""+1 ,user);
        return Result.success(flag);
    }

    @RequestMapping("/redis/get")
    @ResponseBody
    public Result<KillUser> redisGet(){
        KillUser user =  redisService.get(UserKey.getById,""+1,KillUser.class);
        return Result.success(user);
    }




}
